<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <link rel="stylesheet" href="../../static/kye-map.min.css" />
  <style>
    html,
    body,
    #container {
      width: 100%;
      height: 100%;
    }

    .input-card {
      display: flex;
      flex-direction: column;
      min-width: 10rem;
      word-wrap: break-word;
      background-color: #fff;
      background-clip: border-box;
      border-radius: .25rem;
      border-radius: 0.4rem;
      box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
      position: fixed;
      bottom: 1rem;
      right: 1rem;
      padding: 0.75rem 1.25rem;
    }

    .input-item {
      position: relative;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      width: 100%;
    }

    h4 {
      font-family: inherit;
      font-weight: 300;
      color: inherit;
      font-size: 1.1rem;
      margin-top: 0;
      margin-bottom: .5rem;
    }

    .btn {
      font-weight: 400;
      border: 1px solid transparent;
      color: #25A5F7;
      border-color: #25A5F7;
      line-height: 1.5;
      border-radius: 1rem;
      cursor: pointer;
    }
  </style>
  <title>地图创建与销毁</title>
</head>

<body>
  <div id="container"></div>
  <div class="input-card" style="width:10rem">
    <h4>创建、销毁地图</h4>
    <div id="btns">
      <div class="input-item">
        <button id="create-btn" class="btn" style="margin-right:1rem;">创建地图</button>
        <button id="destroy-btn" class="btn">销毁地图</button>
      </div>
    </div>
  </div>
  <script src="../../static/kye-map.min.js"></script>
  <script>
    var map = null;

    function createMap() {
      if (map) { return }
      map = new KMap.Map('container', {
        resizeEnable: true
      });
      console.log("创建地图成功");
    }

    function destroyMap() {
      map && map.destroy();
      map = null
      console.log("地图已销毁");
    }

    //初始化地图
    createMap();

    //绑定创建、销毁事件
    document.querySelector("#create-btn").onclick = createMap;
    document.querySelector("#destroy-btn").onclick = destroyMap;
  </script>
</body>

</html>